/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.edu.nju.software.AtoClient;

import cn.edu.nju.software.AtoB.DetailSystemInterface;
import java.io.IOException;
import java.io.PrintWriter;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author zf
 */
@WebServlet(name="ConsumeServlet", urlPatterns={"/ConsumeServlet"})
public class ConsumeServlet extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException, RemoteException, NotBoundException {
        response.setContentType("text/html;charset=UTF-8");
        String gid = request.getParameter("gid");
        String gnumber = request.getParameter("gnumer");
        String gtime = request.getParameter("gtime");
        DetailSystemInterface dsi = (DetailSystemInterface) Naming.lookup("rmi:/127.0.0.1:1099/DetailSystemInterface");
			//调用远程方法
        boolean abilityForSale = dsi.submitRequest(Integer.parseInt(gid),Integer.parseInt(gnumber));//obj is the rmi object from salesystem

        PrintWriter out = response.getWriter();
        try {
            if(abilityForSale)
                out.write("true");
            else
                out.write("false");
            /* TODO output your page here
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ConsumeServlet</title>");  
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ConsumeServlet at " + request.getContextPath () + "</h1>");
            out.println("</body>");
            out.println("</html>");
            */
        } finally { 
            out.close();
        }
    } 

}
